package com.cn.zmc.design.builder;

public class BuilderPattern {

    public static void main(String[] args) {
        BuilderFace builder = new Builder();
        Builder build = builder.create().filedA("a").filedB("b").filedC("c").build();
        System.out.println(build.toString());
    }





    public static interface BuilderFace {

        Builder create();
        Builder filedA(String filedA);

        Builder filedB(String filedB);

        Builder filedC(String filedC);

        Builder build();
    }

    public static class Builder implements BuilderFace{

        String filedA;

        String filedB;

        String filedC;

        @Override
        public Builder create() {
            return new Builder();
        }

        @Override
        public Builder filedA(String filedA) {
            this.filedA = filedA;
            return this;
        }

        @Override
        public Builder filedB(String filedB) {
            this.filedB = filedB;
            return this;
        }

        @Override
        public Builder filedC(String filedC) {
            this.filedC = filedC;
            return this;
        }

        @Override
        public Builder build() {
            return this;
        }

        @Override
        public String toString() {
            return "Builder{" +
                    "filedA='" + filedA + '\'' +
                    ", filedB='" + filedB + '\'' +
                    ", filedC='" + filedC + '\'' +
                    '}';
        }
    }
}
